﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Lsk.Business;
using Lsk.Business.DTO;
using Lsk.Data;
using Newtonsoft.Json;

namespace lsk.Web.Api
{
    public class BlogController : ApiController
    {
        [HttpGet]
        public IEnumerable<GetBlog_Result> GetBlog(String url)
        {
            Blog blog = new Blog();
            IEnumerable<GetBlog_Result> results = blog.GetBlog(url);
            return results;
        }

        [HttpPost]
        public IEnumerable<CreateBlog_Result> CreateBlog(dynamic data)
        {
            Blog blog = new Blog();
            Mobile_Blog entry = JsonConvert.DeserializeObject<Mobile_Blog>(data.ToString());
            IEnumerable<CreateBlog_Result> results = blog.CreateBlog(entry.url, entry.title, entry.metatitle, entry.metadescription, entry.keywords, entry.contents);
            return results;
        }

        [HttpPut]
        public IEnumerable<UpdateBlog_Result> UpdateBlog(dynamic data)
        {
            Blog blog = new Blog();
            Mobile_Blog entry = JsonConvert.DeserializeObject<Mobile_Blog>(data.ToString());
            IEnumerable<UpdateBlog_Result> results = blog.UpdateBlog(entry.url, entry.title, entry.metatitle, entry.metadescription, entry.keywords, entry.contents);
            return results;
        }

        [HttpDelete]
        public IEnumerable<DeleteBlog_Result> DeleteBlog(String url)
        {
            Blog blog = new Blog();
            IEnumerable<DeleteBlog_Result> results = blog.DeleteBlog(url);
            return results;
        }
    }
}
